[VB.Net] TreeView update bug in the .net framework

Posted by CFP on Stack Overflow See other posts from Stack Overflow or by CFP
Published on 2010-06-05T21:32:34Z Indexed on 2010/06/05 21:52 UTC
Read the original article Hit count: 219

Filed under:
|
|
|

Consider the following code:

Dim Working As Boolean = False
Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
    If Working Then Exit Sub
    Working = True
    e.Node.Checked = Not e.Node.Checked
    Working = False
End Sub

Private Sub TreeView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseClick
    If e.Button = Windows.Forms.MouseButtons.Right Then MsgBox("Checked = " & TreeView1.SelectedNode.Checked)
End Sub

Where TreeView1 is a TreeView added to the form, with CheckBoxes set to true and one node added. The code basically cancel any node checking occuring on the form.

Single-clicking the top node to check it works well : your click is immediately canceled. Yet if you double-click the checkbox, it will display a tick. But verifying the check state through a right click will yield a Checked = False dialog.

How come? Is it a bug (I'm using the latest .Net Framework 4.0, and he same occurs in 2.0), or am I doing something wrong here? Is there a work around?

Thanks!

EDIT: Additionally, the MouseDoubleClick event is not raised before you click once again.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about treeview